<template>
  <view class="activity">
    <view
      class="activity-item"
      v-for="item in list"
      :key="item.id"
      @click="handleClick(item)"
    >
      <image :src="item.img" class="img"></image>
    </view>
    <u-loadmore :status="moreLoading" :load-text="loadText" />
    <LoginDialog
      ref="loginDialog"
      @loginSuccessBack="loginSuccessBack"
    ></LoginDialog>
  </view>
</template>

<script>
import { env } from "@/api/root";

import {
  addBuryingPoint,
  getTokenByPersonId,
  getCardTypeConfig,
} from "@/api/modules/career";
import LoginDialog from "@/components/LoginDialog";
export default {
  components: {
    LoginDialog,
  },
  data() {
    return {
      cardTypeList: [],
      webToken: "",

      list: [
        {
          id: "careerPathGoods",
          title: "职途机",
          path: "/pagesSub/nationalCollegeEntranceExamination/selectMenu/index",
          img: this.$imgBaseSelf + "/career/careerPathGoodsBanner.jpg",
        },
        // {
        //   id: "subjectSelect",
        //   title: "高考选科",
        //   path: "/pagesSub/nationalCollegeEntranceExamination/selectMenu/index",
        //   img: "https://img3.job1001.com/ypMp/elan/images/subjectSelect/subjectSelectActivityBanner.png",
        // },
        // {
        //   id: "resumeDiagnosis",
        //   title: "简历诊断",
        //   path: "/pagesSub/career/activity/ResumeDiagnosis?fromWhere=discovery", // fromWhere是用于区分从发现进去和从职途进去，从发现进去要付费，职途不用付费
        //   img: this.$imgBaseSelf + "career/resume-zd.png",
        // },
        // {
        //   id: "resume",
        //   title: "简历工坊",
        //   path: "/pagesSub/career/activity/resume",
        //   img: this.$imgBaseSelf + "career/workshop.jpg",
        // },
        {
          id: "ztk",
          title: "职途卡",
          path: "/pagesSub/userCenter/careerPathV2/index",
          img: this.$imgBaseSelf + "career/zhitukaEnter.png",
        },
        // {
        //   id: "mark",
        //   title: "三分查专业",
        //   path: "/pagesSub/careerNew/positionDictionary/MajorSearchSub",
        //   img: this.$imgBaseSelf + "career/advertise/advertise_inner_image.jpg",
        // },
        // {
        //   id: "poster",
        //   title: "中学生入口",
        //   path: "/pagesSub/careerGrow/collegeAdvertise/index",
        //   img:
        //     this.$imgBaseSelf + "career/positionDictionary/poster-banner.jpg",
        // },
        // {
        //   id: "vocationalAssessment", //职业测评
        //   title: "职场守护兽",
        //   path: "/pagesSub/career/activity/vocationalAssessment",
        //   img: this.$imgBaseSelf + "career/assessment_banner.png",
        // },
        // {
        //   id: "aiInterview",
        //   title: "AI面评",
        //   path: "/pagesSub/careerNew/aiInterview/AIInterviewActivity",
        //   img: this.$imgBaseSelf + "career/activity_center_ai_inter_view.png",
        // },
        // {
        //   id: "sxh",
        //   title: "双选会",
        //   path: "/pagesSub/activity/sxh/index",
        //   img: this.$imgBaseSelf + "zph/sxh/banner.png",
        // },
        // {
        //   id: "zty",
        //   title: "职体验",
        //   path: "/pagesSub/zty/index",
        //   img: "https://img3.job1001.com/ypMp/elan/images/careerPath/zty/ztyEntrance.png",
        // },
        {
          id: "ztysybg",
          title: "职业生涯报告",
          path: "/pagesSub/nationalCollegeEntranceExamination/selectMenu/index",
          img: this.$imgBaseSelf + "/career/ztysybg.png",
        },
      ],
      moreLoading: "nomore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "已经到底啦",
      },
      buryingPointId: "",
      cardType: "",
    };
  },
  methods: {
    async getCardTypeConfigFn() {
      const params = {
        ecCode: "freeReportCardTypes",
      };
      const res = await getCardTypeConfig(params);
      if (res.code == 200) {
        console.log("res", res);
        this.cardTypeList = res.data;
      }
    },
    async getTokenByPersonIdFn() {
      const params = {
        personId: uni.getStorageSync("person-id").slice(2),
      };
      const res = await getTokenByPersonId(params);
      if (res.code == 200) {
        console.log("res", res);
        this.webToken = "Bearer " + res.data.token;
      }
    },
    //普通的埋点+事件停留埋点
    async addBuryingPointFn(
      etId,
      statType,
      jumpPersonId,
      jumpSource,
      sourceType
    ) {
      const params = {
        etId: etId,
        id: this.buryingPointId ? this.buryingPointId : "", //后台要求不能传空，未登录也要统计
        personId: uni.getStorageSync("person-id").slice(2) || "0",
        cardType: this.cardType
          ? this.cardType
          : uni.getStorageSync("cardType") || this.cardType,
        consultantId: uni.getStorageSync("sellId")
          ? uni.getStorageSync("sellId")
          : "",
        originType: this.originFrom == "shareLink" ? 10 : 20,
        statType: statType ? statType : "10",
        jumpPersonId: jumpPersonId,
        jumpSource: jumpSource,
        sourceType: sourceType,
      };
      const res = await addBuryingPoint(params);
    },
    async handleClick(item) {
      if (item.title == "中学生入口") {
        wx.reportEvent("activityBanner_collegeAdvertise_click", {}); //首页弹窗进入营销页
        this.addBuryingPointFn(20078, "", "", "", "");
        uni.navigateTo({
          url: "/pagesSub/careerGrow/careerSearch/index",
        });
      } else if (item.title == "职途机") {
        // let personId = uni.getStorageSync("person-id").slice(2) || undefined;
        // if (!personId) {
        //   this.showLoginDialog();
        //   return;
        // }
        this.addBuryingPointFn(40054, "", "", "", "");
        uni.navigateToMiniProgram({
          appId: "wx614f8a78fff34162",
          path: "/ec_goods/detail?vid=0&productInstanceId=16868908125&id=136568247100125&essharewid=11162409245&share_vid=6016925489125&pmc=3%7C5.essharewid.0-3.vid.0-2%7C3%7C5.share_vid.86400",
          success(res) {},
          fail(err) {},
        });
      } else if (item.title == "职业生涯报告") {
        await this.getCardTypeConfigFn();
        let url;
        if (env == "test" || env == "local") {
          url =
            "https://career-h5test.yl1001.com/careerReport/#/reportVertical?token=";
          this.webToken;
        } else {
          url =
            "https://career-h5.yl1001.com/careerReport/#/reportVertical?token=" +
            this.webToken;
        }
        let cardType = uni.getStorageSync("cardType");
        console.log("cardType", cardType, this.cardTypeList);
        if (this.cardTypeList.includes(cardType)) {
          uni.reLaunch({
            url:
              "/pagesSub/public/web/descWebView?link=" +
              encodeURIComponent(url),
          });
        } else {
          uni.showToast({
            icon: "none",
            title: "你暂未参与该活动~",
            duration: 2000,
          });
        }
      } else {
        uni.navigateTo({
          url: item.path + "?fromtag=activity",
        });
      }
    },
    showLoginDialog() {
      this.$refs.loginDialog.setVisibility(true);
    },
  },
  created() {
    this.getTokenByPersonIdFn();
  },
};
</script>

<style lang="scss" scoped>
.activity {
  padding: 32rpx;
  height: 100%;
  overflow: auto;

  &-item {
    height: 240rpx;
    margin-bottom: 24rpx;
    background-color: #eee;
    border-radius: 16rpx;
    overflow: hidden;

    .img {
      width: 100%;
      height: 100%;
      border-radius: 16rpx;
    }
  }
}
</style>
